<?php 
namespace app\common\controller;

use think\Controller;
use app\common\model\shop\ShopClassify;

class Classify extends Controller
{
	/**
	 * 获取分类列表
	 * @return array
	 */
	public function getClassifyList($all = false)
	{
		if($all){
			$list = ShopClassify::where(['state' => 1,'parent_id' => 0])->select();
		}else{
			$list = ShopClassify::where(['state' => 1,'parent_id' => 0])->paginate(5)->toArray();
		}
		$data = $all ? $list : $list['data'];
		foreach ($data as &$rows) {
			$child = ShopClassify::where(['state' => 1,'parent_id' => $rows['id']])->select();
			foreach ($child as &$row) {
				$row['open'] = false;
				$childs = ShopClassify::where(['state' => 1,'parent_id' => $row['id']])->select();
				foreach ($childs as &$val) {
					$val['label'] = $val['name'];
					$val['value'] = $val['id'];
				}
				$row['children'] = $childs;
				$row['label'] = $row['name'];
				$row['value'] = $row['id'];
			}
			$rows['children'] = $child;
			$rows['open'] = false;
			$rows['label'] = $rows['name'];
			$rows['value'] = $rows['id'];
		}
		if($all){
			$list = $data;
		}else{
			$list['data'] = $data;
		}
		return $list;
	}
}